package org.budo.support.javax.sql.wrapper;

import java.sql.Connection;
import java.sql.SQLException;

import javax.sql.DataSource;

import org.budo.support.assertion.Assert;

/**
 * @author li
 * @version 1 (2014年11月5日 下午1:22:32)
 * @since Java7
 */
public class DataSourceWrapper extends CommonDataSourceWrapper implements DataSource {
    private DataSource dataSource;

    public DataSourceWrapper() {}

    public DataSourceWrapper(DataSource dataSource) {
        this.setDataSource(dataSource);
    }

    public <T> T unwrap(Class<T> iface) throws SQLException {
        return this.getDataSource().unwrap(iface);
    }

    public boolean isWrapperFor(Class<?> iface) throws SQLException {
        return this.getDataSource().isWrapperFor(iface);
    }

    public Connection getConnection() throws SQLException {
        return this.getDataSource().getConnection();
    }

    public Connection getConnection(String username, String password) throws SQLException {
        return this.getDataSource().getConnection(username, password);
    }

    public DataSource getDataSource() {
        Assert.notNull(this.dataSource, "#41 dataSource is null, this=" + this);

        return this.dataSource;
    }

    public void setDataSource(DataSource dataSource) {
        this.dataSource = dataSource;

        this.setCommonDataSource(dataSource);
    }
}